const jwt = require('jsonwebtoken')
const { PRIVATE_KEY } = require('../config/serect')

class LoginController {
  
  async sign(ctx, next) {
    const { id, name } = ctx.user

    // 颁发token令牌
    const payload = { id,name}
    const token = jwt.sign(payload, PRIVATE_KEY, {
      expiresIn: 60*60*24,
      algorithm: 'RS256'
    })

    ctx.body = {
      code:200,
      data:{ id,name,token }
    }
  }
}

module.exports = new LoginController()